project(agent C ASM)

set(src
    drivers/usbd.c
    drivers/usbtty.c
    drivers/usbphy.c
    drivers/circbuf.c
    drivers/timer.c
    drivers/simple/mmc.c
    drivers/simple/hacc.c
    boot.S
    main.c
    usbproto.c
    efuse.c
    bootinfo.c
    bootkernel.c
    util.S
    pt.c
    secpol.c
    partition_rw.c
    test.c
    ltest.S
    patchkernel.c
    trustzone.c
    bootrom.c
    ram_console.c
)

add_executable(agent ${src})
target_link_libraries(agent rtl rtl-kmode)
target_include_directories(agent PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
target_link_options(agent PRIVATE -T ${CMAKE_SOURCE_DIR}/linker.ld -nostdlib)

# temporary workaround
target_link_libraries(agent ${N1_RTL_PATH}/clang-runtime/runtime-arm32.a)

add_custom_command(
    TARGET agent
    POST_BUILD
    COMMAND arm-none-eabi-objcopy -O binary "${CMAKE_CURRENT_BINARY_DIR}/agent" "${CMAKE_BINARY_DIR}/agent.bin"
)
